package mop.model;

import mop.exception.IllegalDescriptionException;
import mop.exception.IllegalIdException;

/**
 * Abstract Model Class with description
 * in the name of Pull Up refactoring
 * 
 * @invar 	Description is valid.
 *  		| hasValidDescription()
 *  
 * @author MOP Team 7
 */

public abstract class AbstractModelWithDescription extends AbstractModel implements ModelWithDescriptionInterface
{


	
	/**
	 * Abstract Constructor
	 * 
	 * @param id			The identifier for Model object
	 * @param description 	The description for Model object
	 * 
	 * @effect call super constructor
	 * 	super(id)
	 * 
	 * @effect	(Tries to) set the description.
	 * 			| setDescription(description)
	 * 
	 * @throws  IllegalDescriptionException
	 * 			Thrown when the description is invalid.
	 * @throws IllegalIdException 
	 * 			Thrown when the id is invalid
	 */
	public AbstractModelWithDescription(String id, String description) throws IllegalDescriptionException, IllegalIdException
	{
		super(id);
		setDescription(description);
	}

	/***************************************************************************
	 * 					AbstractDescriptionModel description
	 ***************************************************************************/
	


	/**
	  * Checks whether the given description is valid (not empty and not null).
	  * 
	  * @param 		description
	  *  			The description to checked.
	  * 
	  * @return 	True if the given description is not empty and not null, otherwise false.
	  */
	 public static boolean isValidDescription(String description)
	 {
		 return (description != null && (!(description.trim().equals(""))));
	 }
	
	 /**
	  * Returns whether this Project object has a valid description or not.
	  * 
	  * @return		True if the description of this object is valid, otherwise false.
	  */
	 public boolean hasValidDescription()
	 {
		 return isValidDescription(this.getDescription());
	 }
	 
	/**
	 * set the description
	 * 
	 * @param description
	 * 
	 * @post 		The description is set.
	 * 			| this.getDescription().equals(description)
	 * @throws 	IllegalDescriptionException 
	 *       		Thrown when the description is invalid.
	 *       		| ! isValidDescription(description) 
	 */
	private void setDescription(String description) throws IllegalDescriptionException
	{
		if(!isValidDescription(description))
			 throw new IllegalDescriptionException(description);
		this.description = description;
	}
	
	/**
	 * Returns the description
	 * 
	 * @return description
	 */
	public String getDescription()
	{
		return this.description;
	}
	
	/** the description -> this is used to fetch the description */
	protected String description = null;
}
